package edu.cs346.group5.ui.userpages;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.URL;

import javax.imageio.ImageIO;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;

import edu.cs346.group5.datastores.Topic;
import edu.cs346.group5.logic.Profile;
import edu.cs346.group5.logic.ViewTopic;
import edu.cs346.group5.ui.forumpages.view_topic;

public class WishListPopup extends JDialog {

	private final JPanel contentPanel = new JPanel();

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			//WishListPopup dialog = new WishListPopup();
			//dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			//dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the dialog.
	 */
	public WishListPopup(final int itemId, final int userId, String topic, final int listItemIndex, final DefaultListModel model,final boolean isUser) {
		setBounds(100, 100, 206, 176);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setLayout(new FlowLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		{
			JLabel lblTopic = new JLabel("");
			contentPanel.add(lblTopic);
			lblTopic.setText(topic);
		}
		if(isUser)
		{
			JButton btnDeleteFromWish = new JButton("Delete From Wish List");
			contentPanel.add(btnDeleteFromWish);
			btnDeleteFromWish.addActionListener(
					new ActionListener(){
						public void actionPerformed(ActionEvent e)
						{
							model.removeElementAt(listItemIndex);
							Profile.DeleteTopicFromWishList(userId, itemId);
							dispose();
						}
	
					}
				);
		}
		{
			JButton btnViewTopic = new JButton("View Topic");
			contentPanel.add(btnViewTopic);
			btnViewTopic.addActionListener(
					new ActionListener(){
						public void actionPerformed(ActionEvent e)
						{
							Topic topic = ViewTopic.GetTopic(itemId);
							view_topic x = new view_topic(topic);
							x.setVisible(true);
							dispose();
						}
	
					}
				);
		}
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton cancelButton = new JButton("Cancel");
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
				getRootPane().setDefaultButton(cancelButton);
				cancelButton.addActionListener(
					new ActionListener(){
						public void actionPerformed(ActionEvent e)
						{
							dispose();
						}
	
					}
				);
			}
		}
	}

}
